package com.mapper;

import com.bean.Orders;
import com.bean.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/* 与orders相关的 CRUD */
public interface OrderMapper {
    /* 查询所有的订单,与此同时查询出来每个订单对应的用户*/

    //1.查询订单信息
    @Select("select * from orders")
    //封装数据 - results代替 resultMap标签
    @Results({
            /*
                property:要封装到Orders中的那个属性,实体类的属性名
                column:数据库中的字段名
                id = true: 标记是主键字段,替代id标签
             */
            @Result(property = "id",column = "id",id = true),
            @Result(property = "ordertime",column = "ordertime"),
            @Result(property = "total",column = "total"),
            @Result(property = "uid",column = "uid"),
            //user属性的封装
            @Result(
                    property = "user",
                    javaType = User.class,
                    column = "uid",
                    //根据当前的uid查询该订单所属的用户信息
                    one = @One(
                            select = "com.mapper.UserMapper.findById",
                            fetchType = FetchType.EAGER)
            )
    })
    public List<Orders> findAllUser();


}
